
    export default {
        data () {
            return {
                nsearch:null,
                value:null,
                name:0,
                total:null,
                num:0,
                modal1:false,
                columns7: [
                    {
                        title: 'Name',
                        key: 'product',
                        render: (h, params) => {
                            return h('div', [
                                h('Icon', {
                                    props: {
                                        type:this.showlogo(params.row.type),
                                        color:'orange',
                                        size:'20px'
                                    }
                                }),
                                h('strong', params.row.product)
                            ]);
                        }
                    },
                    {
                        title: 'Price',
                        key: 'price'
                    },
                    {
                        title: 'Place',
                        key: 'place'
                    },
                    {
                        title: 'Action',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small',
                                        icon:'edit'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            //this.show(params.index);
                                            this.num=params.index
                                            this.modal1 = true;
                                        }
                                    }
                                }, 'update'),
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.show(params.index)
                                        }
                                    }
                                }, 'View'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.index);
                                        }
                                    }
                                }, 'Delete')
                            ]);
                        }
                    }
                ],
               data6: [],
                data1:{
                    page:null,
                    limit:null,
                }
            }
        },
        created(){
          // 在初始化阶段，去请求nodejs的api，返回来json数据
        this.get();
         // this.getall();
          console.log(this.data6[0]);
        },
        methods: {
            getData(){
                var type='全部';
                 this.$http({
                method:'post',
                data:{
                    page: this.data1.page,
                    limit:this.data1.limit
                },
              url:`http://10.31.153.25:3000/product/list/${type}`
            })
              .then((response) => {
                    this.total=response.data.total;
                    this.data6 = response.data.docs;
              })
            },
            page(page){
                this.data1.page=page;
                this.getData();
            },
            get(data){
                this.data1.limit=data||10;
                this.getData();
            },
            ok (name) {
                this.$Message.info('点击了确定');

            },
            cancel () {
                this.$Message.info('点击了取消');
            },
            updata(data){
                console.log(data)
                this.$http({
                          method: 'put',
                          url:`http://10.31.153.25:3000/product/data/${data._id}`,
                          data: data
                        }).then(res=>{
                          this.getData();
                          this.success(true,"更新")

                         // 重置form表单内容为数据的初始值状态
                         // ********** 非常重要
                         Object.assign(this.$data.formValidate, 
                         this.$options.data().formValidate);


                        }) 
            },
            showlogo(a){
                if(a=='手机'){
                    return 'iphone';
                }else if(a=='图书'){
                    return 'ios-book';
                }else{
                    return 'tshirt';
                }
            },
            show (index) {
                this.$Modal.info({
                    title: 'User Info',
                   content: `产品名：${this.data6[index].product}<br>生产地：${this.data6[index].place}<br>价格：${this.data6[index].price}<br>类型：${this.data6[index].type}`
                })
            },
            remove (index) {
                const data=this.data6[index];
                this.data6.splice(index, 1);        
                this.$http({
                 method:'delete',
                 url:`http://10.31.153.25:3000/product/data/${data._id}`
               }).then(res=>{
                 console.log(res);
                 this.getData();
                 this.$Message.success('delete success!');
               })
            },
            // getall(){
            //      this.$http({
            //     method:'post',
            //   url:`http://localhost:3000/product/all`
            // })
            //   .then((response) => {
            //         this.total=response.data.docs.length;
            //         console.log(response);
            //   })
            // },
    		
            changenum(num){
                this.data1.page=num;
                this.getData();

            }, 
            handleReset (name) {
                this.$refs[name].resetFields();
                this.$Message.success('重置成功');
            },    
            success (nodesc,name) {
                this.$Notice.success({
                    title: name+'成功',
                    desc: nodesc ? '' : '成功'
                });
            },
            warning (nodesc,name) {
                this.$Notice.warning({
                    title: name+'失败',
                    desc: nodesc ? '' : 'Here is the notification description. Here is the notification description. '
                });
            },
    }
    }          